<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use Auth;
use App\Http\Requests\UserRequest;
use Illuminate\Support\Facades\Hash;
class UsersController extends Controller
{
    public function index(User $user)
    {
        $user = Auth::user();
        return view('users.index', compact('user'));
    }
    public function edit(User $user)
    {
        $this->authorize('edit_self', $user);
        return view('users.edit', compact('user'));
    }

    public function update(User $user, UserRequest $request)
    {
        $this->authorize('edit_self', $user);
        $qq = $request->qq;
        $user->qq = $qq;
        if ($password = $request->password) {
            $user->password = Hash::make($password);
        }
        $user->update();
        return redirect()->route('users.edit', Auth::id())->with('success', '更新成功');
    }
    public function warning()
    {
        $user = Auth::user();
        return view('users.warning', compact('user'));
    }
}
